#include <reg52.H>
#include "main.h"

unsigned int flag=0,mark=0;
unsigned char KeyNumber;

void main()
{
	Timer0Init();
	DS1302_Init();
	DS1302_SetTime();
	while(1)
	{
		DS1302_ReadTime();
		if(flag%2==0)
		{
			Nixie(1,DS1302_Time[3]/10);		
			Nixie(2,DS1302_Time[3]%10);		
			Nixie(3,14);	
			Nixie(4,DS1302_Time[4]/10);		
			Nixie(5,DS1302_Time[4]%10);		
			Nixie(6,14);	
			Nixie(7,DS1302_Time[5]/10);		
			Nixie(8,DS1302_Time[5]%10);
		}
		if(flag%2==1)
		{
				Nixie(1,2);		
				Nixie(2,0);		
				Nixie(3,(DS1302_Time[0])/10);	
				Nixie(4,(DS1302_Time[0]%10));	
				Nixie(4,12);
				Nixie(5,DS1302_Time[1]/10);
				Nixie(6,DS1302_Time[1]%10);
				Nixie(6,12);		
				Nixie(7,DS1302_Time[2]/10);
				Nixie(8,DS1302_Time[2]%10);	
		}
		KeyNumber=key();
		if(KeyNumber)
		{
			if(KeyNumber==1)
			{
				mark=1;
			}
			if(KeyNumber==2)
			{
				mark=0;
			}
			if(KeyNumber==3)
			{
				flag=0;
			}
			if(KeyNumber==4)
			{
				flag=1;
			}
		}
		
				
	
	}
	
}

void Timer0_Routine() interrupt 1
{
	static unsigned int T0Count;
	TL0 = 0x18;		
	TH0 = 0xFC;
	T0Count++;
	if(mark==1)
	{
		if(T0Count>=2000)
		{
			flag++;
			T0Count=0;
		}
	}
}
	